<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<%@ page contentType="text/html; charset=utf-8"%>
	<%@ include file="/commons/taglibs.jsp"%>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>增加下拉选项</title>
		<%@ include file="/commons/css_js_head.jsp"%>
<script type="text/javascript" src="${ctx }/js/cascadeConnectionMenu.js"></script>
<script type="text/javascript" src="${ctx }/js/xindiqu.js"></script>
<script type="text/javascript">
	
	window.onload=function(){//页面加载完毕后执行此方法
	//初始化各级联菜单，setDefaultAreaCode方法通过地区码参数指定默认显示的地区
	
	var dq = document.getElementById("userMachineType_dqM").value;
	new CascadeConnectionMenu().setDefaultAreaCode(dq).//默认显示"越秀区",
											initByArray('userMachineType.selA',//内容为省的select元素的name（字符串）或id值
											shengArray,//内容为所有省的数组对象
											'userMachineType.selB',//内容为市的select元素的name（字符串）或id值
											shiArray,//内容为所有市的数组对象
											'userMachineType.selC',//内容为区的select元素的name（字符串）或id值
											quArray);//内容为所有区的数组对象
	}
		
</script>		
<script type="text/javascript">

doReturnUrl = "${ctx }/base/userMachineTypeAction!doList.ts?code=${code}";
doUpdateUrl = "${ctx }/base/userMachineTypeAction!doUpdate.ts";

//验证用户名称
function checkUserName() {

	var name = document.getElementById("userMachineType.name");
	var optionsName = document.getElementById("optionsName");
	
	if(name.value == ""){
		var innerHtml = "<span class='ts_red'>请输入用户名称！<\/span>";
		cleanData(name,optionsName,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(optionsName,innerHtml);
		return true;
	}
}


function checkForm(){
	
	if(
		
		checkUserName() 
		){
		return true;
	}else{
		return false;
	}
}

//用于更新的时候删除配置信息的参数id
var deleId = "";

//保存更新
function doUpdate1() {

	var _form = document.forms[0];
	if (doUpdateUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}
	
	    var name = document.getElementById("userMachineType.name").value;
		var nameSpan = document.getElementById("name");
		if(name.replace(/[ ]/g,"") == ""){
			//var innerHtml = "<span class='ts_red'>名称不能为空！<\/span>";
			//cleanData(name,nameSpan,innerHtml);
			alert("名称不能为空！");
			return false;
		}else{
	
		_form.action = doUpdateUrl+"?deleId="+deleId;
		_form.submit();
		
		onCancel();
		parent.window.location.reload();
		}
	
}

function doUpdate2(){
    if (doUpdateUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}
	var name = document.getElementById("userMachineType.name").value;
	var nameSpan = document.getElementById("name");
	document.getElementById("userMachineType_deleId").value= deleId;
	
	if(name.replace(/[ ]/g,"") == ""){
		
		alert("名称不能为空！");
		return false;
	}else{
	
	$("#form1").ajaxSubmit({
	
		async: false,
		type: "POST",
		dataType:"json",
		cache: false,
		
		success: function(date){
		 	
			if(date=="1")
			{
				alert("操作成功");
				window.close();
				parent.window.location.reload();
			}
			else
			{
				alert("出现错误，请与管理员联系！");
				window.close();
				parent.window.location.reload();
			}
		}
	});
}
}

//关闭小窗口
function onCancel()
{
	closeWindow();
}
function closeWindow()
{
	self.parent.tb_remove();
}

function addRowkv() { 
var confName = document.getElementById("confName").value; 
var confValue = document.getElementById("confValue").value; 
 
if(confName.replace(/[ ]/g,"") == "" ){
 alert("请输入正确的名称");
  document.getElementById("confName").focus();
  return;
}
if(confValue.replace(/[ ]/g,"") == ""){
 alert("请输入名称对应的值");
   document.getElementById("confValue").focus();
   return;
}

           //添加一行 
var newTr = fzjcTbl.insertRow(fzjcTbl.rows.length-1); 
//添加六列 
var newTd0 = newTr.insertCell(); 
var newTd1 = newTr.insertCell();
var newTd2 = newTr.insertCell(); 
var newTd3 = newTr.insertCell(); 
var newTd4 = newTr.insertCell(); 
var newTd5 = newTr.insertCell(); 
var newTd6 = newTr.insertCell(); 
//设置列内容和属性 

var tname = document.getElementById("confName").value;
var tvalue = document.getElementById("confValue").value;
var confLength1 = document.getElementById("confLength").value;//定义长度
newTd0.innerHTML = '<input type=checkbox  onClick="GetRow()" value="'+confName+"_"+confValue+',"  name="bizNumbershy" align="center" checked="true"/>名称：'; 
newTd1.innerHTML= '<input type=text name="tname" value="'+tname+'"  /><font color="red"></font>';
newTd2.innerHTML= "定义值长度："; 
newTd3.innerHTML= '<input type=text name="diylength" maxlength="2" value="'+confLength1+'" style="width:30px;"  /><font color="red"></font>';
newTd4.innerHTML= "值："; 
newTd5.innerHTML= '<input type=text name="tvalue" value="'+tvalue+'"  /><font color="red"></font>';
newTd6.innerHTML= "<a href=# onclick='theDelHy()'>删除</a>";

document.getElementById("confName").value="";
document.getElementById("confValue").value="";
document.getElementById("confName").focus();

}

//删除单独一行
function theDelHy(nvid){	
	deleId = deleId+nvid+"-";
	var fzjcTbl = document.getElementById("fzjcTbl");
	cGetRow=window.event.srcElement.parentElement.parentElement.rowIndex; 
	var ro = fzjcTbl.rows[cGetRow];
	//debugger;
	var rcn = ro.cells[2];
	var rcp = ro.cells[3];
	fzjcTbl.deleteRow(cGetRow);	  				
}
//校验修改行的自定义值
function checkRow(){
	var fzjcTbl = document.getElementById("fzjcTbl");
	var pp=window.event.srcElement; 
	
    for (var i=0; i < fzjcTbl.rows.length; i++) //遍历table的行,

    {
     
     if(pp==fzjcTbl.rows[i].cells[5].getElementsByTagName("input")[0]) //cells[2]为触发事件的列的索引

     { //判断是否是触发事件的A标签
      var confLength1 = fzjcTbl.rows[i].cells[3].getElementsByTagName("input")[0].value;//定义长度
      var str = fzjcTbl.rows[i].cells[5].getElementsByTagName("input")[0].value;
     
      var confLength2 = fzjcTbl.rows[i].cells[5].getElementsByTagName("input")[0].value.length;//输入长度
      var str1 = confLength2+"";
      if(confLength2!=confLength1 && confLength1!="")
	   {
	     fzjcTbl.rows[i].cells[5].getElementsByTagName("input")[0].value= str1.substr(0, str1.length-1);
	    alert("不符合自定义长度!长度应为 "+confLength1+",实际为 "+confLength2);
	     
	     return false;
	   }
     } 
    
    }
}

function checkTable(obj){
 
  if(obj.value=="")
   {
     alert("取消自定义长度!");return false;
   }
   else
  {
     if(checkNumber(obj.value)==false)
     {
      alert("只能输入数字");
      obj.value="";
      return false;
      }
    }
 
}
function checkNumber(str)//检查是否为数字
{
    var reg = /^[0-9]+$/;
    if(!reg.test(str))
    {
        return false;
    }
    return true;
}
function validate()
{
   var obj=document.getElementById("confLength");
   if(obj.value=="")
   {
     alert("不能为空!");
     return false;
   }
   else
  {
     if(checkNumber(obj.value)==false)
     {
      alert("只能输入数字");
      document.getElementById("confLength").value="";
      return false;
      }
    }
}
function valiLength()
{
   
   var confLength1 = document.getElementById("confLength").value;//定义长度
   var confLength2 = document.getElementById("confValue").value.length;//输入长度

   if(confLength2!=confLength1&&confLength1!="")
   {
     alert("不符合自定义长度!长度应为 "+confLength1+",实际为 "+confLength2);
     document.getElementById("confValue").value="";
     //document.getElementById("confValue").focus();
     return false;
   }
   
}
</script>
	</head>

	<body style="overflow-x: hidden">
		<div class="mTitle">
			<span class="hidsearch"></span>
			<b class="bbig">修改信息终端类型</b> 带
			<b class="fred"> * </b>号为必填项
		</div>

		<form action="userMachineTypeAction!doUpdate.ts" method="post" id="form1" namespace="/base">
			<!-- 隐藏的信息 -->
			<s:hidden name="userMachineType.theIdMachine"></s:hidden>
			<s:hidden name="userMachineType.optionName"></s:hidden>
			<s:hidden name="userMachineType.userId"></s:hidden>
			<s:hidden name="userMachineType.deleId"></s:hidden>
			<s:hidden name="userMachineType.optionId"></s:hidden>
			<s:hidden name="userMachineType.dqM"></s:hidden>
			<!--list -->
			<div class="mainAdd">
				<table class="addTable">

					
					<tr>
						<th>
							<b class="fred"> * </b> 信息终端名称：
							
						</th>
						<td >
							<s:textfield name="userMachineType.name" readonly="true" maxlength="32" theme="simple" />
							<span id="name"></span>
						</td>
						
					</tr>
					<tr>
						<th width="10%">
							<b class="fred">*</b>区域：
						</th>
						<td width="40%" colspan="3">
						省：<select name="userMachineType.selA" style="width:140" value="" id="userMachineType_selA"></select>
 			  市：<select name="userMachineType.selB" style="width:140" value="" id="userMachineType.selB"></select>
  			  区：<select name="userMachineType.selC" style="width:140" value="" id="userMachineType.selC"></select>
						</td>
					</tr>
					<tr>
						<th>
							<b class="fred"> * </b> 类型：
						</th>
						<td>
						     <s:select
                                 theme="simple"
                                 name="userMachineType.optionId"
                                 list="#request.list" 
                                 cssStyle="width:83px;"	
                                 listKey="theId" 
                                 listValue="name"
                			     id="select"
                			     disabled="true"
                			     >
							</s:select>
						</td>
						
					</tr>
				
					<table   class="addTable" id="fzjcTbl">
				<c:forEach var="arr" items="${machineTypeNameValueList}">
				       	<tr valign="top">
				       		<input type="hidden" name="nvid" value="${arr.nvid }"/>
					        <td width="72" class="td2"><input type=checkbox  onClick="GetRow()" value=""  name="mcname" align="center" checked="true"/>名称：</td>
					        <td width="168"><input type="text" name="tname" value="${arr.name }"/> <font color="red">*</font></td>
					        <td width="100" class="td2">定义值长度： </td>
					        <td width="16"><input type="text" name="diylength" value="${arr.diylength }" maxlength="3" onblur="return checkTable(this)" style="width:30px;"/> </td>
					        <td width="11" class="td2">值：</td>
					        <td width="168"><input type="text"  name="tvalue" value="${arr.value }" onblur="return checkRow()" /> <font color="red">*</font></td>
					        <td width="75" class="td2"><a href=# onclick='theDelHy("${arr.nvid}")'>删除</a></td>
						</tr>
			      	</c:forEach>
			     		 <tr valign="top">
					        <td width="72" class="td2">自定义名称： </td>
					        <td width="168"><input type="text" name="1tname" id="confName"/> <font color="red">*</font></td>
					        <td width="100" class="td2">定义值长度： </td>
					        <td width="16"><input type="text" name="diy" id="confLength" maxlength="3 onblur="return validate()" style="width:30px;"/> </td>
					        <td width="11" class="td2">值：</td>
					        <td width="168"><input type="text" name="1confValue" id="confValue" onblur="return valiLength()"/> <font color="red">*</font></td>
					        <td width="75" class="td2"><input class="btn" type="button" value="添加值" onclick="addRowkv()"/></td>
						</tr>
				</table>
					

				</table>
			</div>
			<!--end list -->
			<div class="addToolbar">
				<p>
					<input class="btn" name="btn_confirm" value="确定" type="button"
						onclick="doUpdate2()" />
					<input class="btn" name="btn_return" value="返回" type="button"
						onclick="onCancel()" />
				</p>
			</div>

		</form>

	</body>

<script type="text/javascript">
//document.getElementById("options.name").focus();

document.onkeydown = function(e) {
	if (!e)
		e = window.event;//火狐中是 window.event
	if ((e.keyCode || e.which) == 13) {
		doSave();
	}
}
</script>
</html>
